]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Add and implement new D-Bus method
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sat, 28 Oct 2023 22:21:05 +0000 (19:21 -0300)
committerMarge Bot <marge-bot@gnome.org>
Thu, 21 Dec 2023 17:59:17 +0000 (17:59 +0000)
The new InteractiveScreenshot() D-Bus method is implemented using
the signals introduced by the previous commit, and is fundamentally
very simple: take the screenshot, and return the GFile URI.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2999>

data/dbus-interfaces/org.gnome.Shell.Screenshot.xml
js/ui/screenshot.js

index 528b01ecba671db3e1d77f8efe2a3ca450c2400a..8e16a30a628dc8dc3308a5702ee75ae673b91d26 100644 (file)
   -->
   <interface name="org.gnome.Shell.Screenshot">
 
+    <!--
+        InteractiveScreenshot:
+        @success: whether the screenshot was captured
+        @uri: the file where the screenshot was saved
+
+        Shows Shell's interactive screenshot dialog, and lets the
+        user take an interactive screenshot, which is then returned
+        in @filename as png image. It returns a boolean indicating
+        whether the operation was successful or not. The URI of the
+        screenshot will be returned in @uri.
+    -->
+    <method name="InteractiveScreenshot">
+      <arg type="b" direction="out" name="success"/>
+      <arg type="s" direction="out" name="uri"/>
+    </method>
+
     <!--
         Screenshot:
         @filename: The filename for the screenshot
index bfe2f788099461fb4782712ceac1786a519ec0b5..a1206a56d671182669116eb303d78be7c048099c 100644 (file)
@@ -2604,6 +2604,34 @@ export class ScreenshotService {
         }
     }
 
+    async InteractiveScreenshotAsync(params, invocation) {
+        try {
+            await this._senderChecker.checkInvocation(invocation);
+        } catch (e) {
+            invocation.return_gerror(e);
+            return;
+        }
+
+        Main.screenshotUI.connectObject(
+            'screenshot-taken', (ui, file) => {
+                Main.screenshotUI.disconnectObject(invocation);
+                invocation.return_value(new GLib.Variant('(bs)', [true, file.get_uri()]));
+            },
+            'closed', () => {
+                Main.screenshotUI.disconnectObject(invocation);
+                invocation.return_value(new GLib.Variant('(bs)', [false, '']));
+            },
+            invocation);
+
+
+        try {
+            Main.screenshotUI.open(UIMode.SCREENSHOT_ONLY);
+        } catch (e) {
+            Main.screenshotUI.disconnectObject(invocation);
+            invocation.return_value(new GLib.Variant('(bs)', [false, '']));
+        }
+    }
+
     async SelectAreaAsync(params, invocation) {
         try {
             await this._senderChecker.checkInvocation(invocation);